package cn.kattomy.shop.categorysecond.dao.impl;

import java.util.List;

import cn.kattomy.shop.base.dao.BaseDao;
import cn.kattomy.shop.categorysecond.dao.CategorySecondDao;
import cn.kattomy.shop.categorysecond.vo.CategorySecond;

public class CategorySecondDaoImpl extends BaseDao implements CategorySecondDao{

	@Override
	public int findCount() {
		String hql = "select count(*) from CategorySecond";
		List<Long> list = getSession().createQuery(hql).list();
		if (list != null && list.size() > 0) {
			return list.get(0).intValue();
		}
		return 0;
	}

	@Override
	public List<CategorySecond> findByPageNo(int begin, int pageSize) {
		String hql= "from CategorySecond order by csid desc";
		List<CategorySecond> list = getSession().createQuery(hql).setFirstResult(begin).setMaxResults(pageSize).list();
		if (list != null && list.size() > 0) {
			return list;
		}
		return null;
	}

	@Override
	public void save(CategorySecond categorysecond) {
		getSession().save(categorysecond);
	}

	@Override
	public void delete(CategorySecond categorysecond) {
		getSession().delete(categorysecond);
	}

	@Override
	public CategorySecond findByCsid(Integer csid) {
		return (CategorySecond) getSession().get(CategorySecond.class, csid);
	}

	@Override
	public void update(CategorySecond categorySecond) {
		getSession().update(categorySecond);
	}

	@Override
	public  List<CategorySecond> findAll() {
		String hql = "from CategorySecond";
		List<CategorySecond> list = getSession().createQuery(hql).list();
		return list;
	}
	
}
